<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">
    <ui:define name="head-title">
        <title>Make Payment for Customer | Merlion's ERP System</title>
    </ui:define>
    
    
    <ui:define name="content">
        <f:view beforePhase="#{addSupplierInvoiceManagerBean.initView}">
        <h:form>
            <p:panel id="panel" header="Create Invoice for Supplier"> 
                <p:ajaxStatus style="width:16px;height:16px;">   
                    <f:facet name="start">   
                        <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                    </f:facet> 
 
                    <f:facet name="complete">   
                        <h:outputText value="" />   
                    </f:facet>   
                </p:ajaxStatus> 
 
                <p:messages /> 
                    
                    
                    <h:outputLabel for="supplierName" style="font-weight: bold" value="Search Company: " /> 
                    <p:autoComplete value="#{addSupplierInvoiceManagerBean.supplierName}" required="true"
                                    id="supplierName" label="supplierName" requiredMessage="Supplier Name is required." completeMethod="#{addSupplierInvoiceManagerBean.complete}">
                    </p:autoComplete>
                        <p:message for="supplierName" />                         
                        
                        <br></br>
                        
            <p:fieldset legend="List of completed Material Orders" rendered="#{addSupplierInvoiceManagerBean.isExisting}">
                <h:panelGrid columns="6" cellpadding="10">      
                    <p:dataTable var="materialOrder" value="#{addSupplierInvoiceManagerBean.selectedSupplier.materialOrderList}"
                                     emptyMessage="No Material Orders found." style="width: 50%;" selection="#{addSupplierInvoiceManagerBean.selectedMaterialOrder}" >
                        
                    <p:column selectionMode="single"/>
                    <p:column sortBy="#{materialOrder.materialOrderId}">
                        <f:facet name="header">
                            <h:outputText value="Material Order ID"/>
                        </f:facet>
                        <h:outputText value="#{materialOrder.materialOrderId}"/>
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Date"/>
                        </f:facet>
                        <h:outputText value="#{materialOrder.currentDate}" style="width: 150px"/>
                    </p:column>
                    
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Total Price"/>
                        </f:facet>
                        <h:outputText value="#{materialOrder.totalPrice}" style="width: 150px"/>
                    </p:column>
                    
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Status"/>
                        </f:facet>
                        <h:outputText value="#{materialOrder.materialOrderState}" style="width: 150px"/>
                    </p:column>
                        </p:dataTable>
                        
                        
                </h:panelGrid>
            </p:fieldset>                        
                
                        <br></br>
                <p:commandButton value="Retrieve Information" update="panel" actionListener="#{addSupplierInvoiceManagerBean.retrieve}" ajax="true" rendered="#{addSupplierInvoiceManagerBean.isNotExisting}"/>
                <p:commandButton value="View order details" update="panel" actionListener="#{addSupplierInvoiceManagerBean.viewOrderDetails}" ajax="true" rendered="#{addSupplierInvoiceManagerBean.isExisting}"/>
                
                <br></br>
                <br></br>
                <p:fieldset legend="Material Order Details" rendered="#{addSupplierInvoiceManagerBean.isSelectedMaterialOrder}">
                    <h:panelGrid columns="6" cellpadding="10" >
                        
                        <p:dataTable var="materialLine" value="#{addSupplierInvoiceManagerBean.selectedMaterialOrder.materialLines}"
                                     emptyMessage="No Material Orders found." style="width: 50%;">
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Material Type"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.rawMaterial.materialType}" style="width: 150px"/>
                            </p:column>
                            
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Lot Size"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.rawMaterial.lotSize}" style="width: 150px"/>
                            </p:column>
                            
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Lot Quantity"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.lotQuantity}" style="width: 150px"/>
                            </p:column>
                            
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Total Quantity"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.finalPrice}" style="width: 150px"/>
                            </p:column>
                            
                            <f:facet name="footer">
                                <h:outputText value="Total Price :"/>
                                <h:outputText value="#{addSupplierInvoiceManagerBean.selectedMaterialOrder.totalPrice}"/>
                            </f:facet>
                        </p:dataTable>
                        
                        
                    </h:panelGrid>
                    
                    
                    <h:outputText value="Invoice Amount :"/>
                    <h:inputText value="#{addSupplierInvoiceManagerBean.invoiceAmount}"/>
                            
                    <p:commandButton value="Create Invoice" update="panel" actionListener="#{addSupplierInvoiceManagerBean.createInvoice}" ajax="true" />
                    
                </p:fieldset>
                </p:panel> 
        </h:form>
        </f:view>
        
    </ui:define>

</ui:composition>
